<template>
  <div class="sql-agent-setting">

    <el-row class="sql-agent-setting-info">
      <div>
        <img src="@/assets/mspbots/logo.png"
             height="36"
             alt="MSPBOTS Portal"
             style="cursor: pointer;" />
      </div>
      <p>version: {{version}}</p>
      <p>
        Product:
        <a target="blank"
           @click="openBrower('https://app.maibozhineng.com')">app.maibozhineng.com</a>
      </p>
      <p>
        Landing Page:
        <a target="blank"
           @click="openBrower('https://mspbots.ai')">mspbots.ai</a>
      </p>
      <p>
        Support:
        <a>support@mspbots.ai</a>
      </p>

      <div class="upgrade-history">
        <p v-for="(item,index) in versionList"
           :key="index"
           :title="`Updated to version ${item.version} at ${item.time} on ${item.date}`">Updated to version {{item.version}} at {{item.time}} on {{item.date}}</p>
      </div>
      <el-pagination v-show="total > 1"
                     layout="prev, pager, next"
                     :total="total"
                     :current-page="versionParams.pageIndex"
                     style="text-align:center;margin-top: 15px;"
                     @current-change="handleCurrentChange">
      </el-pagination>
    </el-row>

    <!-- <el-row type="flex">
      <el-col :span="24" class="run">
        <el-row>
          <el-col :span="12">
            <p>
              <span>{{info.PullConfigTime}}</span>
              <span>Mins</span>
            </p>
            <span>Pull the configuration interval</span>
          </el-col>
          <el-col :span="12">
            <p>
              <span>{{info.SyncTaskTime}}</span>
              <span>Mins</span>
            </p>
            <span>Synchronization task interval</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <p>
              <span>{{info.HealthTime}}</span>
              <span>Mins</span>
            </p>
            <span>Send me online intervals</span>
          </el-col>
          <el-col :span="12">
            <p>
              <span>{{info.IsDatabaseTime}}</span>
              <span>Mins</span>
            </p>
            <span>Check whether the database is connected properly</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <p>
              <span>{{info.RetryCount}}</span>
            </p>
            <span>Retry times of synchronizing data</span>
          </el-col>
          <el-col :span="12">
            <p>
              <span>{{_.upperFirst(info.IsStopTask)}}</span>
            </p>
            <span>Whether to suspend a task</span>
          </el-col>
        </el-row>
      </el-col>

    </el-row> -->
  </div>
</template>
<script>
export default {
  data () {
    return {
      info: {},
      versionParams: {
        pageSize: 10,
        pageIndex: 1
      },
      versionList: [],
      total: 0,
      version: undefined
    }
  },
  created () {
    this.getInfo()
    this.getVersion()
    this.getVersionPage()
  },
  methods: {
    async getInfo () {
      const { data: res } = await this.$interface.sqlAgent.client()
      this.info = res
    },
    async getVersion () {
      const { data: res } = await this.$interface.sqlAgent.clientVersion()

      if (res) {
        this.version = res.version
      }
    },
    async getVersionPage () {
      const { data: res } = await this.$interface.sqlAgent.getVersionPage(this.versionParams)

      if (res.list && res.list.length > 0) {
        this.total = res.count
        res.list.forEach((item) => {
          const _d = item.CreateTime.split(' ')
          const version = {
            version: item.Number,
            date: _d[0],
            time: _d[1]
          }
          this.versionList.push(version)
        })
      }
    },
    handleCurrentChange (current) {
      this.versionParams.pageIndex = current
      this.getVersionPage()
    },
    openBrower (url) {
      this.$interface.sqlAgent.openBrowser({ url })
    }

  }
}
</script>
<style lang="scss" scoped>
.block {
  background: #fff;
  box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.04);
  border-radius: 4px 4px 4px 4px;
  padding: 8px;
  box-sizing: border-box;
}
.sql-agent-setting {
  height: 100%;
  font-family: Segoe UI-Semibold, Segoe UI;

  &-info {
    padding: 50px 15px 15px 15px;
    margin-bottom: 15px;
    text-align: center;
    height: 100%;
    display: flex;
    flex-direction: column;
    @extend .block;
    & > div:nth-child(1) {
      width: 170px;
      background: #001a68;
      margin: 0 auto 20px;
      border-radius: 4px;
    }
    a {
      text-decoration: none;
      color: #000;
      &:hover {
        text-decoration: underline;
        cursor: pointer;
      }
    }
    & > p {
      margin: 0;
      &:nth-child(2) {
        font-size: 30px;
        font-weight: bold;
        margin-bottom: 10px;
      }
      &:not(:nth-child(2)) {
        margin-bottom: 5px;
      }
    }
    .upgrade-history {
      border: 1px solid rgba(0, 0, 0, 0.08);
      margin-top: 15px;
      height: 200px;
      overflow-y: auto;
      position: relative;
      flex: 1;
      &:empty::after {
        content: "No Data";
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        color: #909399;
      }
      p {
        margin: 0;
        height: 30px;
        line-height: 30px;
        width: 100%;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
      }
    }
  }
  .run {
    padding-top: 30px;
    position: relative;
    &::before {
      content: "Operating parameters";
      position: absolute;
      top: 0;
      left: 0;
    }
    .el-row {
      display: flex;
      &:not(:last-child) {
        margin-bottom: 15px;
      }
    }
    .el-col {
      min-height: 150px;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      @extend .block;
      &:nth-child(2n-1) {
        margin-right: 15px;
      }
      p {
        margin: 0;
        font-weight: bold;
        margin-bottom: 10px;
        span:nth-child(1) {
          font-size: 36px;
        }
      }
    }
  }
}
</style>
